<template>
  <div>
    <a-button type="primary" @click="openImportWin">导入节点</a-button>

    <excel-paste
      :columnsExcel="excel"
      :exportXlsTemplateUrl="exportXlsTemplateUrl"
      :exportXlsTemplateRequestUrl="exportXlsTemplateRequestUrl"
      :excelVisible="excelVisible"
      :excelConfirmLoading="excelConfirmLoading"
      @handleOkExcel="handleOkExcel"
      @handleCancelExcel="handleCancelExcel"
    ></excel-paste>
  </div>
</template>

<script>
import ExcelPaste from '@/components/excelPaste/ExcelPaste'
import { httpAction, getAction, postAction, postActionAsync } from '@/api/manage'

export default {
  components: {
    ExcelPaste,
  },
  data() {
    return {
      url: {
        addBatch: '/projectBuild/importMaProject',
      },
      excelVisible: false,
      columnsExcel: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
          isImportExcelColumns: false,
        },
        {
          title: '创建人id',
          align: 'center',
          dataIndex: 'createUserId',
        },
        {
          title: '创建人姓名',
          align: 'center',
          dataIndex: 'createUserName',
        },
        {
          title: '任务单名称',
          align: 'center',
          dataIndex: 'taskName',
        },
        {
          title: '任务单完成目标',
          align: 'center',
          dataIndex: 'target',
        },
        {
          title: '计划完成时间',
          align: 'center',
          dataIndex: 'endDate',
        },
        {
          title: '开始时间',
          align: 'center',
          dataIndex: 'startDate',
        },
        {
          title: '主导经营体id',
          align: 'center',
          dataIndex: 'mainDeptId',
        },
        {
          title: '主导经营体名称',
          align: 'center',
          dataIndex: 'mainDeptName',
        },
      ],
      maExecel: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
          isImportExcelColumns: false,
        },
        {
          title: '项目名称',
          align: 'center',
          dataIndex: 'projectName',
        },
        {
          title: '二级分类',
          align: 'center',
          dataIndex: 'twoTypeName',
        },
        {
          title: '是否参加五比五拼',
          align: 'center',
          dataIndex: 'hasJoin',
        },
        {
          title: '比拼类型',
          align: 'center',
          dataIndex: 'competitionTypeName',
        },
        {
          title: '三级分类',
          align: 'center',
          dataIndex: 'threeTypeName',
        },
        {
          title: '主导经营体',
          align: 'center',
          dataIndex: 'mainDeptName',
        },
        {
          title: '落地团队',
          align: 'center',
          dataIndex: 'landingDeptName',
        },
        {
          title: '是否攻克或突破',
          align: 'center',
          dataIndex: 'hasConquer',
        },
        {
          title: '经济效益',
          align: 'center',
          dataIndex: 'budgetCost',
        },
        {
          title: '现状或问题',
          align: 'center',
          dataIndex: 'presentSituation',
        },
        {
          title: '改进措施',
          align: 'center',
          dataIndex: 'improvement',
        },
        {
          title: '收益计算方法',
          align: 'center',
          dataIndex: 'incomeMethod',
        },
        {
          title: '取数规则',
          align: 'center',
          dataIndex: 'accessRule',
        },
        {
          title: '项目推进涉及的协作经营体数量',
          align: 'center',
          dataIndex: 'answerOne',
        },
        {
          title: '项目产出/投入比值为',
          align: 'center',
          dataIndex: 'answerTwo',
        },
        {
          title: '项目的收益达成率为',
          align: 'center',
          dataIndex: 'answerThree',
        },
        {
          title: '项目经验可推广范围',
          align: 'center',
          dataIndex: 'answerFour',
        },
        {
          title: '项目周期-完成工作内容',
          align: 'center',
          dataIndex: 'jobContent',
        },
        {
          title: '收益计算周期-开始时间',
          align: 'center',
          dataIndex: 'planStartDate',
        },
        {
          title: '收益计算周期-计划完成时间',
          align: 'center',
          dataIndex: 'completionDate',
        },
        {
          title: '项目经理',
          align: 'center',
          dataIndex: 'projectManagerId',
        },
        {
          title: '项目副经理',
          align: 'center',
          dataIndex: 'projectSubManagerId',
        },
        {
          title: '项目成员',
          align: 'center',
          dataIndex: 'projectMemberId',
        },
        {
          title: '项目财务',
          align: 'center',
          dataIndex: 'projectMoneyMemberId',
        },
        {
          title: '建议人',
          align: 'center',
          dataIndex: 'ideaUserId',
        },
        {
          title: '1月项目进度',
          align: 'center',
          dataIndex: 'oneMonthProcess',
        },
        {
          title: '1月项目收益',
          align: 'center',
          dataIndex: 'oneMonthMoney',
        },
      ],
      excel: [],
      maTwoExcel: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
          isImportExcelColumns: false,
        },
        {
          title: 'id',
          align: 'center',
          dataIndex: 'projectBuildId',
        },
        {
          title: 'ideaUserId',
          align: 'center',
          dataIndex: 'ideaUserId',
        },
        // {
        //   title: '项目编号',
        //   align: 'center',
        //   dataIndex: 'projectNo',
        // },
        // {
        //   title: '项目名称',
        //   align: 'center',
        //   dataIndex: 'projectName',
        // },
        // {
        //   title: '项目推进涉及的协作经营体数量',
        //   align: 'center',
        //   dataIndex: 'answerOne',
        // },
        // {
        //   title: '项目产出/投入比值为',
        //   align: 'center',
        //   dataIndex: 'answerTwo',
        // },
        // {
        //   title: '项目的收益达成率为',
        //   align: 'center',
        //   dataIndex: 'answerThree',
        // },
        // {
        //   title: '项目经验可推广范围',
        //   align: 'center',
        //   dataIndex: 'answerFour',
        // },
      ],
      exportXlsTemplateUrl: 'templates/excel/时间表导入模板.xls',
      exportXlsTemplateRequestUrl: '/common/exportXlsTemplate',
      excelConfirmLoading: false,
      type: this.$route.query.type,
    }
  },
  created() {
    this.excel = this.type && this.type == 2 ? this.maTwoExcel : this.maExecel
    this.url.addBatch = this.type && this.type == 2 ? '/projectBuild/importMaProjectTwo' : '/projectBuild/importMaProject'
  },
  methods: {
    openImportWin: function () {
      this.excelVisible = true
    },
    handleOkExcel: function (data) {
      this.excelDataSource = []
      for (let index = 0; index < data.length; index++) {
        console.log(data[index])
      }
      this.excelDataSource = data
      //数据验证
      this.excelConfirmLoading = true
      postAction(this.url.addBatch, { excelVOList: data })
        .then((res) => {
          this.excelConfirmLoading = false
          if (res.code === 200) {
            this.excelVisible = false
            this.$message.success('导入成功')
          } else {
            this.$message.warning('操作异常:' + res.message)
          }
        })
        .catch((res) => {
          this.excelConfirmLoading = false
          this.$message.warning('操作异常:' + res.message)
        })
    },
    handleCancelExcel: function () {
      this.excelVisible = false
    },
  },
}
</script>

<style lang="less" scoped>
</style>